﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class SkillPanel : MonoBehaviour, IObserver<UIEventType>
{
    void Awake()
    {
        ObserverManager.ui_observer.AddListener(this, UIEventType.AddSkill); 
        ObserverManager.ui_observer.AddListener(this, UIEventType.RemoveSkill);
    }

    void Start()
    { 
    }

    public void EventHandler(UniEventArgs<UIEventType> args)
    {
        switch (args.eventType)
        {
            case UIEventType.AddSkill:
                Dictionary<KeyCode, Skill> currentSkillDic = (Dictionary<KeyCode, Skill>)args.content;
                if (currentSkillDic.ContainsKey(KeyCode.W))
                {
                    this.transform.GetChild(1).GetComponent<Image>().sprite = Resources.Load(currentSkillDic[KeyCode.W].skillSprite, typeof(Sprite)) as Sprite;
                }
                if (currentSkillDic.ContainsKey(KeyCode.E))
                {
                    this.transform.GetChild(2).GetComponent<Image>().sprite = Resources.Load(currentSkillDic[KeyCode.E].skillSprite, typeof(Sprite)) as Sprite;
                }
                if (currentSkillDic.ContainsKey(KeyCode.R))
                {
                    this.transform.GetChild(3).GetComponent<Image>().sprite = Resources.Load(currentSkillDic[KeyCode.R].skillSprite, typeof(Sprite)) as Sprite;
                }
                break;
            case UIEventType.RemoveSkill:
                KeyCode keyCode = (KeyCode)args.content;
                switch (keyCode)
                {
                    case KeyCode.W:
                        this.transform.GetChild(1).GetComponent<Image>().sprite = null;
                        break;
                    case KeyCode.E:
                        this.transform.GetChild(2).GetComponent<Image>().sprite = null;
                        break;
                    case KeyCode.R:
                        this.transform.GetChild(3).GetComponent<Image>().sprite = null;
                        break;
                }
                break;
        }
    }
}
